home *** CD-ROM | disk | FTP | other *** search
- /* Purpose - validate the search string */
-
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "ctype.h"
- #include "werr.h"
-
- extern int s_type,leading,trailing,wildcards;
-
- int validate(char *string,int exact)
- {
- char *pointer,temp[80];
- char *string_to_lower(char *string);
-
- leading = trailing = wildcards = 0;
-
- strcpy(temp,string_to_lower(string));
- pointer = temp;
- if (*pointer != '*') {
- if (isdigit(*pointer)) s_type = 0; /* then is a code */
- else if (isalpha(*pointer) || ispunct(*pointer)) s_type = 1; /* then is a town */
- else {
- werr(0,"Syntax error in search string. Please re-enter search string.");
- return 0;
- }
- }
- else {
- leading = 1;
- pointer++;
- if (*pointer == '*') {
- werr(0,"Syntax error in search string. Only one leading wildcard allowed.");
- return 0;
- }
- if (isdigit(*pointer)) s_type = 0; /* then is a code */
- else if (isalpha(*pointer) || ispunct(*pointer)) s_type = 1; /* then is a town */
- else {
- werr(0,"Syntax error in search string. Please re-enter search string.");
- return 0;
- }
- }
-
- pointer = temp + strlen(temp) - 1; /* point to last character */
- if (*pointer == '*') trailing = 1;
-
- /* finally check that there are not more than 2 wildcards */
- pointer = temp;
- while(*pointer) if(*pointer++ == '*') wildcards++;
- if (wildcards > 2) {
- werr(0,"Syntax error in search string. Too many wildcards present.");
- return 0;
- }
- if (exact && wildcards) {
- werr(0,"Error - cannot have an exact search with wildcards. Please try again");
- return 0;
- }
- return 1; /* if here then all is OK */
- }
-